﻿using MediatR;
using S.Eartag.API.Application.Command.SheepFileConditionCommand;
using S.Eartag.Infrastructure.Interface;

namespace S.Eartag.API.Application.CommandHandlers.SheepFileConditionCommandHandler
{
    public class SheepFileConditionAuricleUpdateCommandHandler : IRequestHandler<SheepFileConditionAuricleUpdateCommand, int>
    {
        private readonly ISheepFileRepository sheepFileRepository;

        public SheepFileConditionAuricleUpdateCommandHandler(ISheepFileRepository sheepFileRepository)
        {
            this.sheepFileRepository = sheepFileRepository;
        }

        public async Task<int> Handle(SheepFileConditionAuricleUpdateCommand request, CancellationToken cancellationToken)
        {

            var res = sheepFileRepository.All().Result.Where(x => x.EarNumber == request.EarNumber).FirstOrDefault();
            res.Cottage=request.Cottage;
            res.Field=request.Field;
            return await sheepFileRepository.Update(res);
        }
    }
}
